Trò chơi Tic-Tac-Toe, game đánh caro full source code
- PhotonLagSimulationGui.cs
- PhotonNetwork /
- Plugins /
- Photon Unity Networking /
- Assets /
- project /
2 /// \file
3 /// <summary>Part of the [Optional GUI](@ref optionalGui).</summary>
4 #pragma warning restore 1587
5
6
7 using ExitGames.Client.Photon;
8 using UnityEngine;
9
10
11 /// <summary>
12 /// This MonoBehaviour is a basic GUI for the Photon client's network-simulation feature.
13 /// It can modify lag (fixed delay), jitter (random lag) and packet loss.
14 /// </summary>
15 /// \ingroup optionalGui
16 public class PhotonLagSimulationGui : MonoBehaviour
17 {
18 /// <summary>Positioning rect for window.</summary>
19 public Rect WindowRect = new Rect(0, 100, 120, 100);
20
21 /// <summary>Unity GUI Window ID (must be unique or will cause issues).</summary>
22 public int WindowId = 101;
23
24 /// <summary>Shows or hides GUI (does not affect settings).</summary>
25 public bool Visible = true;
26
27 /// <summary>The peer currently in use (to set the network simulation).</summary>
28 public PhotonPeer Peer { get; set; }
29
30 public void Start()
31 {
32 this.Peer = PhotonNetwork.networkingPeer;
33 }
34
35 public void OnGUI()
36 {
37 if (!this.Visible)
38 {
39 return;
40 }
41
42 if (this.Peer == null)
43 {
44 this.WindowRect = GUILayout.Window(this.WindowId, this.WindowRect, this.NetSimHasNoPeerWindow, "Netw. Sim.");
45 }
46 else
47 {
48 this.WindowRect = GUILayout.Window(this.WindowId, this.WindowRect, this.NetSimWindow, "Netw. Sim.");
49 }
50 }
51
52 private void NetSimHasNoPeerWindow(int windowId)
53 {
54 GUILayout.Label("No peer to communicate with. ");
55 }
56
57 private void NetSimWindow(int windowId)
58 {
59 GUILayout.Label(string.Format("Rtt:{0,4} +/-{1,3}", this.Peer.RoundTripTime, this.Peer.RoundTripTimeVariance));
60
61 bool simEnabled = this.Peer.IsSimulationEnabled;
62 bool newSimEnabled = GUILayout.Toggle(simEnabled, "Simulate");
63 if (newSimEnabled != simEnabled)
64 {
65 this.Peer.IsSimulationEnabled = newSimEnabled;
66 }
67
68 float inOutLag = this.Peer.NetworkSimulationSettings.IncomingLag;
69 GUILayout.Label("Lag " + inOutLag);
70 inOutLag = GUILayout.HorizontalSlider(inOutLag, 0, 500);
71
72 this.Peer.NetworkSimulationSettings.IncomingLag = (int)inOutLag;
73 this.Peer.NetworkSimulationSettings.OutgoingLag = (int)inOutLag;
74
75 float inOutJitter = this.Peer.NetworkSimulationSettings.IncomingJitter;
76 GUILayout.Label("Jit " + inOutJitter);
77 inOutJitter = GUILayout.HorizontalSlider(inOutJitter, 0, 100);
78
79 this.Peer.NetworkSimulationSettings.IncomingJitter = (int)inOutJitter;
80 this.Peer.NetworkSimulationSettings.OutgoingJitter = (int)inOutJitter;
81
82 float loss = this.Peer.NetworkSimulationSettings.IncomingLossPercentage;
83 GUILayout.Label("Loss " + loss);
84 loss = GUILayout.HorizontalSlider(loss, 0, 10);
85
86 this.Peer.NetworkSimulationSettings.IncomingLossPercentage = (int)loss;
87 this.Peer.NetworkSimulationSettings.OutgoingLossPercentage = (int)loss;
88
89 // if anything was clicked, the height of this window is likely changed. reduce it to be layouted again next frame
90 if (GUI.changed)
91 {
92 this.WindowRect.height = 100;
93 }
94
95 GUI.DragWindow();
96 }
97 }
\file
This MonoBehaviour is a basic GUI for the Photon client's network-simulation feature.
It can modify lag (fixed delay), jitter (random lag) and packet loss.
\ingroup optionalGui
if anything was clicked, the height of this window is likely changed. reduce it to be layouted again next frame